Remove old file-system property. Add new file-system-backend string
authorAlexander Larsson <alexl@redhat.com>
Thu, 19 Feb 2004 07:43:39 +0000 (07:43 +0000)
committerAlexander Larsson <alexl@src.gnome.org>
Thu, 19 Feb 2004 07:43:39 +0000 (07:43 +0000)
2004-02-19  Alexander Larsson  <alexl@redhat.com>

* gtk/gtkfilechooser.c: (gtk_file_chooser_class_init):
* gtk/gtkfilechooserutils.c:
* gtk/gtkfilechooserutils.h:
* gtk/gtkfilechooserwidget.c:
Remove old file-system property.
Add new file-system-backend string property

* gtk/gtkfilechooserdefault.[ch]:
Handle the file-system-backend property

* gtk/gtkfilechooserdialog.[ch]:
(gtk_file_chooser_dialog_new_with_backend):
Remove old file-system property.
Add new file-system-backend string property
Add new function gtk_file_chooser_dialog_new_with_backend

* gtk/gtkfilesystem.c:
* gtk/gtkfilesystem.h:
Add filesystem module support.

15 files changed:
ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilechooser.c
gtk/gtkfilechooserdefault.c
gtk/gtkfilechooserdefault.h
gtk/gtkfilechooserdialog.c
gtk/gtkfilechooserdialog.h
gtk/gtkfilechooserutils.c
gtk/gtkfilechooserutils.h
gtk/gtkfilechooserwidget.c
gtk/gtkfilesystem.c
gtk/gtkfilesystem.h

index eaef75c0f9e9b3f78b366e5ac854648a7102203b..53e1f11230dc37391d71118917f82c5195ac7864 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2004-02-19  Alexander Larsson  <alexl@redhat.com>
+
+       * gtk/gtkfilechooser.c: (gtk_file_chooser_class_init):
+       * gtk/gtkfilechooserutils.c:
+       * gtk/gtkfilechooserutils.h:
+       * gtk/gtkfilechooserwidget.c:
+       Remove old file-system property.
+       Add new file-system-backend string property
+       
+       * gtk/gtkfilechooserdefault.[ch]:
+       Handle the file-system-backend property
+       
+       * gtk/gtkfilechooserdialog.[ch]:
+       (gtk_file_chooser_dialog_new_with_backend):
+       Remove old file-system property.
+       Add new file-system-backend string property
+       Add new function gtk_file_chooser_dialog_new_with_backend
+       
+       * gtk/gtkfilesystem.c: 
+       * gtk/gtkfilesystem.h:
+       Add filesystem module support.  
+
 2004-02-18  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilechooserdefault.c (shortcuts_tree_create): Renamed
index eaef75c0f9e9b3f78b366e5ac854648a7102203b..53e1f11230dc37391d71118917f82c5195ac7864 100644 (file)
@@ -1,3 +1,25 @@
+2004-02-19  Alexander Larsson  <alexl@redhat.com>
+
+       * gtk/gtkfilechooser.c: (gtk_file_chooser_class_init):
+       * gtk/gtkfilechooserutils.c:
+       * gtk/gtkfilechooserutils.h:
+       * gtk/gtkfilechooserwidget.c:
+       Remove old file-system property.
+       Add new file-system-backend string property
+       
+       * gtk/gtkfilechooserdefault.[ch]:
+       Handle the file-system-backend property
+       
+       * gtk/gtkfilechooserdialog.[ch]:
+       (gtk_file_chooser_dialog_new_with_backend):
+       Remove old file-system property.
+       Add new file-system-backend string property
+       Add new function gtk_file_chooser_dialog_new_with_backend
+       
+       * gtk/gtkfilesystem.c: 
+       * gtk/gtkfilesystem.h:
+       Add filesystem module support.  
+
 2004-02-18  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilechooserdefault.c (shortcuts_tree_create): Renamed
index eaef75c0f9e9b3f78b366e5ac854648a7102203b..53e1f11230dc37391d71118917f82c5195ac7864 100644 (file)
@@ -1,3 +1,25 @@
+2004-02-19  Alexander Larsson  <alexl@redhat.com>
+
+       * gtk/gtkfilechooser.c: (gtk_file_chooser_class_init):
+       * gtk/gtkfilechooserutils.c:
+       * gtk/gtkfilechooserutils.h:
+       * gtk/gtkfilechooserwidget.c:
+       Remove old file-system property.
+       Add new file-system-backend string property
+       
+       * gtk/gtkfilechooserdefault.[ch]:
+       Handle the file-system-backend property
+       
+       * gtk/gtkfilechooserdialog.[ch]:
+       (gtk_file_chooser_dialog_new_with_backend):
+       Remove old file-system property.
+       Add new file-system-backend string property
+       Add new function gtk_file_chooser_dialog_new_with_backend
+       
+       * gtk/gtkfilesystem.c: 
+       * gtk/gtkfilesystem.h:
+       Add filesystem module support.  
+
 2004-02-18  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilechooserdefault.c (shortcuts_tree_create): Renamed
index eaef75c0f9e9b3f78b366e5ac854648a7102203b..53e1f11230dc37391d71118917f82c5195ac7864 100644 (file)
@@ -1,3 +1,25 @@
+2004-02-19  Alexander Larsson  <alexl@redhat.com>
+
+       * gtk/gtkfilechooser.c: (gtk_file_chooser_class_init):
+       * gtk/gtkfilechooserutils.c:
+       * gtk/gtkfilechooserutils.h:
+       * gtk/gtkfilechooserwidget.c:
+       Remove old file-system property.
+       Add new file-system-backend string property
+       
+       * gtk/gtkfilechooserdefault.[ch]:
+       Handle the file-system-backend property
+       
+       * gtk/gtkfilechooserdialog.[ch]:
+       (gtk_file_chooser_dialog_new_with_backend):
+       Remove old file-system property.
+       Add new file-system-backend string property
+       Add new function gtk_file_chooser_dialog_new_with_backend
+       
+       * gtk/gtkfilesystem.c: 
+       * gtk/gtkfilesystem.h:
+       Add filesystem module support.  
+
 2004-02-18  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilechooserdefault.c (shortcuts_tree_create): Renamed
index eaef75c0f9e9b3f78b366e5ac854648a7102203b..53e1f11230dc37391d71118917f82c5195ac7864 100644 (file)
@@ -1,3 +1,25 @@
+2004-02-19  Alexander Larsson  <alexl@redhat.com>
+
+       * gtk/gtkfilechooser.c: (gtk_file_chooser_class_init):
+       * gtk/gtkfilechooserutils.c:
+       * gtk/gtkfilechooserutils.h:
+       * gtk/gtkfilechooserwidget.c:
+       Remove old file-system property.
+       Add new file-system-backend string property
+       
+       * gtk/gtkfilechooserdefault.[ch]:
+       Handle the file-system-backend property
+       
+       * gtk/gtkfilechooserdialog.[ch]:
+       (gtk_file_chooser_dialog_new_with_backend):
+       Remove old file-system property.
+       Add new file-system-backend string property
+       Add new function gtk_file_chooser_dialog_new_with_backend
+       
+       * gtk/gtkfilesystem.c: 
+       * gtk/gtkfilesystem.h:
+       Add filesystem module support.  
+
 2004-02-18  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkfilechooserdefault.c (shortcuts_tree_create): Renamed
index 516f24a3f1fdb2e8139e9240795fe5e0e2e1b7fb..08c0811dfc85636e1893b5e398d8587ac5d76bc3 100644 (file)
@@ -95,10 +95,10 @@ gtk_file_chooser_class_init (gpointer g_iface)
                                                          GTK_FILE_CHOOSER_ACTION_OPEN,
                                                          G_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
-                                      g_param_spec_object ("file-system",
-                                                           P_("File System"),
-                                                           P_("File system object to use"),
-                                                           GTK_TYPE_FILE_SYSTEM,
+                                      g_param_spec_string ("file-system-backend",
+                                                           P_("File System Backend"),
+                                                           P_("Name of file system backend to use"),
+                                                           NULL, 
                                                            G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_object ("filter",
index a546c41503f77a5d8e701077cd8a7eb259020455..50ac4eb97812430bd88d7e4260a490b8ac6aeb0c 100644 (file)
 #include "gtktypebuiltins.h"
 #include "gtkvbox.h"
 
+#if defined (G_OS_UNIX)
+#include "gtkfilesystemunix.h"
+#elif defined (G_OS_WIN32)
+#include "gtkfilesystemwin32.h"
+#endif
+
 #include <string.h>
 #include <time.h>
 
@@ -1734,6 +1740,45 @@ set_select_multiple (GtkFileChooserDefault *impl,
   check_preview_change (impl);
 }
 
+static void
+set_file_system_backend (GtkFileChooserDefault *impl,
+                        const char *backend)
+{
+  if (impl->file_system)
+    {
+      g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
+      impl->volumes_changed_id = 0;
+      g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
+      impl->bookmarks_changed_id = 0;
+      g_object_unref (impl->file_system);
+    }
+  
+  impl->file_system = NULL;
+  if (backend)
+    impl->file_system = _gtk_file_system_create (backend);
+  
+  if (!impl->file_system)
+    {
+#if defined (G_OS_UNIX)
+      impl->file_system = gtk_file_system_unix_new ();
+#elif defined (G_OS_WIN32)
+      impl->file_system = gtk_file_system_win32_new ();
+#else
+#error "No default filesystem implementation on the platform"
+#endif
+    }
+  
+  if (impl->file_system)
+    {
+      impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
+                                                  G_CALLBACK (volumes_changed_cb),
+                                                  impl);
+      impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
+                                                    G_CALLBACK (bookmarks_changed_cb),
+                                                    impl);
+    }
+}
+
 static void
 gtk_file_chooser_default_set_property (GObject      *object,
                                       guint         prop_id,
@@ -1762,32 +1807,8 @@ gtk_file_chooser_default_set_property (GObject      *object,
        gtk_widget_hide (impl->new_folder_button);
 
       break;
-    case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM:
-      {
-       GtkFileSystem *file_system = g_value_get_object (value);
-       if (impl->file_system != file_system)
-         {
-           if (impl->file_system)
-             {
-               g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
-               impl->volumes_changed_id = 0;
-               g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
-               impl->bookmarks_changed_id = 0;
-               g_object_unref (impl->file_system);
-             }
-           impl->file_system = file_system;
-           if (impl->file_system)
-             {
-               g_object_ref (impl->file_system);
-               impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
-                                                            G_CALLBACK (volumes_changed_cb),
-                                                            impl);
-               impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
-                                                              G_CALLBACK (bookmarks_changed_cb),
-                                                              impl);
-             }
-         }
-      }
+    case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
+      set_file_system_backend (impl, g_value_get_string (value));
       break;
     case GTK_FILE_CHOOSER_PROP_FILTER:
       set_current_filter (impl, g_value_get_object (value));
@@ -3238,9 +3259,9 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
 }
 
 GtkWidget *
-_gtk_file_chooser_default_new (GtkFileSystem *file_system)
+_gtk_file_chooser_default_new (const char *file_system)
 {
   return  g_object_new (GTK_TYPE_FILE_CHOOSER_DEFAULT,
-                       "file-system", file_system,
+                       "file-system-backend", file_system,
                        NULL);
 }
index 785b896f18e9c82dcc16ab34b9a1330e1032719f..aeaa0965bc2d355d1aaa7812fd977f89c270eea0 100644 (file)
@@ -33,7 +33,7 @@ G_BEGIN_DECLS
 typedef struct _GtkFileChooserDefault      GtkFileChooserDefault;
 
 GType      _gtk_file_chooser_default_get_type (void);
-GtkWidget *_gtk_file_chooser_default_new      (GtkFileSystem *file_system);
+GtkWidget *_gtk_file_chooser_default_new      (const char *file_system);
 
 G_END_DECLS
 
index 79bbec943d6e447c48885711f1bcff63bc398d97..8ce52c3988d3bf9a7f6b981e88c0853369d06780 100644 (file)
@@ -33,13 +33,14 @@ struct _GtkFileChooserDialogPrivate
 {
   GtkWidget *widget;
 
-  GtkFileSystem *file_system;
+  char *file_system;
 };
 
 #define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_DIALOG (o)->priv)
 
 static void gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class);
 static void gtk_file_chooser_dialog_init       (GtkFileChooserDialog      *dialog);
+static void gtk_file_chooser_dialog_finalize   (GObject                   *object);
 
 static GObject* gtk_file_chooser_dialog_constructor  (GType                  type,
                                                      guint                  n_construct_properties,
@@ -109,6 +110,7 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
   gobject_class->constructor = gtk_file_chooser_dialog_constructor;
   gobject_class->set_property = gtk_file_chooser_dialog_set_property;
   gobject_class->get_property = gtk_file_chooser_dialog_get_property;
+  gobject_class->finalize = gtk_file_chooser_dialog_finalize;
 
   widget_class->realize = gtk_file_chooser_dialog_realize;
   widget_class->style_set = gtk_file_chooser_dialog_style_set;
@@ -130,6 +132,14 @@ gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog)
   gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
 }
 
+static void
+gtk_file_chooser_dialog_finalize (GObject *object)
+{
+  GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (object);
+
+  g_free (dialog->priv->file_system);
+}
+
 /* Callback used when the user activates a file in the file chooser widget */
 static void
 file_chooser_widget_file_activated (GtkFileChooser       *chooser,
@@ -155,7 +165,7 @@ gtk_file_chooser_dialog_constructor (GType                  type,
 
   if (priv->file_system)
     priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
-                                "file-system", priv->file_system,
+                                "file-system-backend", priv->file_system,
                                 NULL);
   else
     priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET, NULL);
@@ -185,18 +195,9 @@ gtk_file_chooser_dialog_set_property (GObject         *object,
 
   switch (prop_id)
     {
-    case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM:
-      {
-       GtkFileSystem *file_system = g_value_get_object (value);
-       if (priv->file_system != file_system)
-         {
-           if (priv->file_system)
-             g_object_unref (priv->file_system);
-           priv->file_system = file_system;
-           if (priv->file_system)
-             g_object_ref (priv->file_system);
-         }
-      }
+    case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
+      g_free (priv->file_system);
+      priv->file_system = g_value_dup_string (value);
       break;
     default:
       g_object_set_property (G_OBJECT (priv->widget), pspec->name, value);
@@ -308,6 +309,37 @@ gtk_file_chooser_dialog_screen_changed (GtkWidget *widget,
     set_default_size (GTK_FILE_CHOOSER_DIALOG (widget));
 }
 
+static GtkWidget *
+gtk_file_chooser_dialog_new_valist (const gchar          *title,
+                                   GtkWindow            *parent,
+                                   GtkFileChooserAction  action,
+                                   const gchar          *backend,
+                                   const gchar          *first_button_text,
+                                   va_list               varargs)
+{
+  GtkWidget *result;
+  const char *button_text = first_button_text;
+  gint response_id;
+
+  result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
+                        "title", title,
+                        "action", action,
+                        "file-system-backend", backend,
+                        NULL);
+
+  if (parent)
+    gtk_window_set_transient_for (GTK_WINDOW (result), parent);
+
+  while (button_text)
+    {
+      response_id = va_arg (varargs, gint);
+      gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id);
+      button_text = va_arg (varargs, const gchar *);
+    }
+
+  return result;
+}
+
 /**
  * gtk_file_chooser_dialog_new:
  * @title: Title of the dialog, or %NULL
@@ -332,26 +364,49 @@ gtk_file_chooser_dialog_new (const gchar         *title,
 {
   GtkWidget *result;
   va_list varargs;
-  const char *button_text = first_button_text;
-  gint response_id;
-
-  result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
-                        "title", title,
-                        "action", action,
-                        NULL);
-
-  if (parent)
-    gtk_window_set_transient_for (GTK_WINDOW (result), parent);
-
+  
   va_start (varargs, first_button_text);
+  result = gtk_file_chooser_dialog_new_valist (title, parent, action,
+                                              NULL, first_button_text,
+                                              varargs);
+  va_end (varargs);
 
-  while (button_text)
-    {
-      response_id = va_arg (varargs, gint);
-      gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id);
-      button_text = va_arg (varargs, const gchar *);
-    }
+  return result;
+}
 
+/**
+ * gtk_file_chooser_dialog_new_with_backend:
+ * @title: Title of the dialog, or %NULL
+ * @parent: Transient parent of the dialog, or %NULL
+ * @backend: The name of the specific filesystem backend to use.
+ * @action: Open or save mode for the dialog
+ * @first_button_text: stock ID or text to go in the first button, or %NULL
+ * @Varargs: response ID for the first button, then additional (button, id) pairs, ending with %NULL
+ *
+ * Creates a new #GtkFileChooserDialog with a specified backend. This is
+ * especially useful if you use gtk_file_chooser_set_local_only() to allow
+ * non-local files and you use a more expressive vfs, such as gnome-vfs,
+ * to load files.
+ *
+ * Return value: a new #GtkFileChooserDialog
+ *
+ * Since: 2.4
+ **/
+GtkWidget *
+gtk_file_chooser_dialog_new_with_backend (const gchar          *title,
+                                         GtkWindow            *parent,
+                                         GtkFileChooserAction  action,
+                                         const gchar          *backend,
+                                         const gchar          *first_button_text,
+                                         ...)
+{
+  GtkWidget *result;
+  va_list varargs;
+  
+  va_start (varargs, first_button_text);
+  result = gtk_file_chooser_dialog_new_valist (title, parent, action,
+                                              backend, first_button_text,
+                                              varargs);
   va_end (varargs);
 
   return result;
index 0e19fe4a9af96a6ad48c42d260619559c6cb244c..803085cba1cdc0dfe5e9b76efa2b220663d5fa2a 100644 (file)
@@ -50,12 +50,18 @@ struct _GtkFileChooserDialog
   GtkFileChooserDialogPrivate *priv;
 };
 
-GType      gtk_file_chooser_dialog_get_type (void);
-GtkWidget *gtk_file_chooser_dialog_new      (const gchar         *title,
-                                            GtkWindow           *parent,
-                                            GtkFileChooserAction action,
-                                            const gchar         *first_button_text,
-                                            ...);
+GType      gtk_file_chooser_dialog_get_type         (void);
+GtkWidget *gtk_file_chooser_dialog_new              (const gchar          *title,
+                                                    GtkWindow            *parent,
+                                                    GtkFileChooserAction  action,
+                                                    const gchar          *first_button_text,
+                                                    ...);
+GtkWidget *gtk_file_chooser_dialog_new_with_backend (const gchar          *title,
+                                                    GtkWindow            *parent,
+                                                    GtkFileChooserAction  action,
+                                                    const gchar          *backend,
+                                                    const gchar          *first_button_text,
+                                                    ...);
 
 G_END_DECLS
 
index 6cce6fee2233829c4e35bad396024ef7c77f2d6a..d9ca91e7cb7dd41b72fd4baa710d931a77a19536 100644 (file)
@@ -83,8 +83,8 @@ _gtk_file_chooser_install_properties (GObjectClass *klass)
                                    GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET,
                                    "extra-widget");
   g_object_class_override_property (klass,
-                                   GTK_FILE_CHOOSER_PROP_FILE_SYSTEM,
-                                   "file-system");
+                                   GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND,
+                                   "file-system-backend");
   g_object_class_override_property (klass,
                                    GTK_FILE_CHOOSER_PROP_FILTER,
                                    "filter");
index 038114140cf5defe45bdc6f70bdfc45bce33de0b..16c0f09de9b7661eee53d94da03e7c5f7c76034c 100644 (file)
@@ -29,7 +29,7 @@ G_BEGIN_DECLS
 typedef enum {
   GTK_FILE_CHOOSER_PROP_FIRST                  = 0x1000,
   GTK_FILE_CHOOSER_PROP_ACTION                 = GTK_FILE_CHOOSER_PROP_FIRST,
-  GTK_FILE_CHOOSER_PROP_FILE_SYSTEM,
+  GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND,
   GTK_FILE_CHOOSER_PROP_FILTER,
   GTK_FILE_CHOOSER_PROP_FOLDER_MODE,            
   GTK_FILE_CHOOSER_PROP_LOCAL_ONLY,
index f0cd8e8188bc6e5ba78f7ca4c396577a79931b5e..2e9d3bef4d3e46a2264a5e2b7db1096963399934 100644 (file)
 #include "gtkfilechooserutils.h"
 #include "gtktypebuiltins.h"
 
-#if defined (G_OS_UNIX)
-#include "gtkfilesystemunix.h"
-#elif defined (G_OS_WIN32)
-#include "gtkfilesystemwin32.h"
-#endif
-
 struct _GtkFileChooserWidgetPrivate
 {
   GtkWidget *impl;
 
-  GtkFileSystem *file_system;
+  char *file_system;
 };
 
 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)
 
 static void gtk_file_chooser_widget_class_init   (GtkFileChooserWidgetClass *class);
 static void gtk_file_chooser_widget_init         (GtkFileChooserWidget      *chooser_widget);
+static void gtk_file_chooser_widget_finalize     (GObject                   *object);
 
 static GObject* gtk_file_chooser_widget_constructor  (GType                  type,
                                                      guint                  n_construct_properties,
@@ -102,6 +97,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gobject_class->constructor = gtk_file_chooser_widget_constructor;
   gobject_class->set_property = gtk_file_chooser_widget_set_property;
   gobject_class->get_property = gtk_file_chooser_widget_get_property;
+  gobject_class->finalize = gtk_file_chooser_widget_finalize;
 
   _gtk_file_chooser_install_properties (gobject_class);
 
@@ -117,6 +113,14 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
   chooser_widget->priv = priv;
 }
 
+static void
+gtk_file_chooser_widget_finalize (GObject *object)
+{
+  GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
+
+  g_free (chooser->priv->file_system);
+}
+
 static GObject*
 gtk_file_chooser_widget_constructor (GType                  type,
                                     guint                  n_construct_properties,
@@ -134,16 +138,8 @@ gtk_file_chooser_widget_constructor (GType                  type,
 
   gtk_widget_push_composite_child ();
 
-  if (!priv->file_system)
-    {
-#if defined (G_OS_UNIX)
-      priv->file_system = gtk_file_system_unix_new ();
-#elif defined (G_OS_WIN32)
-      priv->file_system = gtk_file_system_win32_new ();
-#endif
-    }
-      
   priv->impl = _gtk_file_chooser_default_new (priv->file_system);
+  
   gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
   gtk_widget_show (priv->impl);
 
@@ -174,18 +170,9 @@ gtk_file_chooser_widget_set_property (GObject         *object,
 
   switch (prop_id)
     {
-    case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM:
-      {
-       GtkFileSystem *file_system = g_value_get_object (value);
-       if (priv->file_system != file_system)
-         {
-           if (priv->file_system)
-             g_object_unref (priv->file_system);
-           priv->file_system = file_system;
-           if (priv->file_system)
-             g_object_ref (priv->file_system);
-         }
-      }
+    case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
+      g_free (priv->file_system);
+      priv->file_system = g_value_dup_string (value);
       break;
     default:
       g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
index de1cb6e8c4c5818da525d137c01da9dc4bd7c8ba..9f2f653f3ccf0274ebf00e68b2daffe9b288ec8c 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-
+#include <gmodule.h>
 #include "gtkfilesystem.h"
 #include "gtkicontheme.h"
+#include "gtkmain.h"
 
 #include <string.h>
 
@@ -886,3 +887,170 @@ gtk_file_paths_free (GSList *paths)
 
   g_slist_free (paths);
 }
+
+/*****************************************
+ *         GtkFileSystem modules         *
+ *****************************************/
+
+typedef struct _GtkFileSystemModule GtkFileSystemModule;
+typedef struct _GtkFileSystemModuleClass GtkFileSystemModuleClass;
+
+struct _GtkFileSystemModule
+{
+  GTypeModule parent_instance;
+  
+  GModule *library;
+
+  void            (*init)     (GTypeModule    *module);
+  void            (*exit)     (void);
+  GtkFileSystem * (*create)   (void);
+
+  gchar *path;
+};
+
+struct _GtkFileSystemModuleClass
+{
+  GTypeModuleClass parent_class;
+};
+
+G_DEFINE_TYPE (GtkFileSystemModule, gtk_file_system_module, G_TYPE_TYPE_MODULE);
+#define GTK_TYPE_FILE_SYSTEM_MODULE       (gtk_file_system_module_get_type ())
+#define GTK_FILE_SYSTEM_MODULE(module)   (G_TYPE_CHECK_INSTANCE_CAST ((module), GTK_TYPE_FILE_SYSTEM_MODULE, GtkFileSystemModule))
+
+
+static GSList *loaded_file_systems;
+
+static gboolean
+gtk_file_system_module_load (GTypeModule *module)
+{
+  GtkFileSystemModule *fs_module = GTK_FILE_SYSTEM_MODULE (module);
+  
+  fs_module->library = g_module_open (fs_module->path, 0);
+  if (!fs_module->library)
+    {
+      g_warning (g_module_error());
+      return FALSE;
+    }
+  
+  /* extract symbols from the lib */
+  if (!g_module_symbol (fs_module->library, "fs_module_init",
+                       (gpointer *)&fs_module->init) ||
+      !g_module_symbol (fs_module->library, "fs_module_exit", 
+                       (gpointer *)&fs_module->exit) ||
+      !g_module_symbol (fs_module->library, "fs_module_create", 
+                       (gpointer *)&fs_module->create))
+    {
+      g_warning (g_module_error());
+      g_module_close (fs_module->library);
+      
+      return FALSE;
+    }
+           
+  /* call the filesystems's init function to let it */
+  /* setup anything it needs to set up. */
+  fs_module->init (module);
+
+  return TRUE;
+}
+
+static void
+gtk_file_system_module_unload (GTypeModule *module)
+{
+  GtkFileSystemModule *fs_module = GTK_FILE_SYSTEM_MODULE (module);
+  
+  fs_module->exit();
+
+  g_module_close (fs_module->library);
+  fs_module->library = NULL;
+
+  fs_module->init = NULL;
+  fs_module->exit = NULL;
+  fs_module->create = NULL;
+}
+
+/* This only will ever be called if an error occurs during
+ * initialization
+ */
+static void
+gtk_file_system_module_finalize (GObject *object)
+{
+  GtkFileSystemModule *module = GTK_FILE_SYSTEM_MODULE (object);
+
+  g_free (module->path);
+
+  G_OBJECT_CLASS (gtk_file_system_module_parent_class)->finalize (object);
+}
+
+static void
+gtk_file_system_module_class_init (GtkFileSystemModuleClass *class)
+{
+  GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
+  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+  
+  module_class->load = gtk_file_system_module_load;
+  module_class->unload = gtk_file_system_module_unload;
+
+  gobject_class->finalize = gtk_file_system_module_finalize;
+}
+
+static void
+gtk_file_system_module_init (GtkFileSystemModule *fs_module)
+{
+}
+
+
+static GtkFileSystem *
+_gtk_file_system_module_create (GtkFileSystemModule *fs_module)
+{
+  GtkFileSystem *fs;
+  
+  if (g_type_module_use (G_TYPE_MODULE (fs_module)))
+    {
+      fs = fs_module->create ();
+      g_type_module_unuse (G_TYPE_MODULE (fs_module));
+      return fs;
+    }
+  return NULL;
+}
+
+
+GtkFileSystem *
+_gtk_file_system_create (const char *file_system_name)
+{
+  struct FileSystemInfo *file_system_info;
+  GSList *l;
+  char *module_path;
+  GtkFileSystemModule *fs_module;
+  GtkFileSystem *fs;
+
+  for (l = loaded_file_systems; l != NULL; l = l->next)
+    {
+      fs_module = l->data;
+      
+      if (strcmp (G_TYPE_MODULE (fs_module)->name, file_system_name) == 0)
+       return _gtk_file_system_module_create (fs_module);
+    }
+
+  fs = NULL;
+  if (g_module_supported ())
+    {
+      module_path = _gtk_find_module (file_system_name, "filesystems");
+
+      if (module_path)
+       {
+         fs_module = g_object_new (GTK_TYPE_FILE_SYSTEM_MODULE, NULL);
+
+         g_type_module_set_name (G_TYPE_MODULE (fs_module), file_system_name);
+         fs_module->path = g_strdup (module_path);
+
+         loaded_file_systems = g_slist_prepend (loaded_file_systems,
+                                                fs_module);
+
+         fs = _gtk_file_system_module_create (fs_module);
+       }
+      
+      g_free (module_path);
+    }
+  
+  return fs;
+}
index 99e726886174b3767917ef752220fe0901314af0..3dc914b2c95a2d6a08d8df86ce051bb9d708e81a 100644 (file)
@@ -335,6 +335,10 @@ GSList *gtk_file_paths_sort (GSList *paths);
 GSList *gtk_file_paths_copy (GSList *paths);
 void    gtk_file_paths_free (GSList *paths);
 
+/* GtkFileSystem modules support */
+
+GtkFileSystem  *_gtk_file_system_create (const char *file_system_name);
+
 G_END_DECLS
 
 #endif /* __GTK_FILE_SYSTEM_H__ */